#ifndef __CCMS_NR_PROCESSES_TAB_H__
#define __CCMS_NR_PROCESSES_TAB_H__

/**
 * @file ccms/nr/processes_tab.h
 *
 * ProcessesTab class header file.
 */

#include "ccms/nr/process.h"
#include <map>
#include <set>

namespace ccms {
namespace nr {

/**
 * Watched processes set.
 */
typedef std::set<pid_t> WatchedProcessesSet;

/**
 * Process objects map indexed by PIDs.
 */
typedef std::map<pid_t, Process> ProcessesMap;

/**
 * ProcessesTab class, holds a group of Process objects and maintains them.
 */
class ProcessesTab
{
    public:
        /**
         * Default constructor.
         */
        ProcessesTab();

        /**
         * Default destructor.
         */
        ~ProcessesTab();

        /**
         * Returns the internal processes map.
         * @return the processes map
         */
        const ProcessesMap& getProcessesMap(void) const;

        /**
         * Returns a process identified by \a pid.
         * @return the process identified by \a pid
         */
        const Process& getProcess(const pid_t pid) const;

        /**
         * Registers a new process to be watched.
         * @param pid - pid of the process to be watched
         */
        void registerWatchedProcess(const pid_t pid);

        /**
         * Unregisters a process that is watched.
         * @param pid - pid of the process not to be watched anymore
         */
        void unregisterWatchedProcess(const pid_t pid);

        /**
         * Performs the update of data from /proc
         */
        void update(void);

    private:
        /**
         * Returns boolean value indicating whether
         * the process identified by pid is to be watched.
         *
         * The check is being done by calling all registered
         * ProcessWatchCallbacks. If no callbacks are registered
         * the function always returns true - all processes
         * are watched.
         * 
         * @param pid - PID of a process to be checked
         *
         * @return true - if the process is to be watched
         * @return false - if the process is not to be watched
         */
        bool isProcessWatched(const pid_t pid) const;

        /**
         * Holds the map of processes indexed by PID
         */
        ProcessesMap processesMap;

        /**
         * Process watch callback list.
         */
        WatchedProcessesSet watchedProcessesSet;
};

} // namespace nr
} // namespace ccms

#endif /* __CCMS_NR_PROCESSES_TAB_H__ */
